﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class HuiyuanDAL
    {
        public HuiyuanDAL(MyContext myContext)
        {
            MyContext = myContext;
        }

        public MyContext MyContext { get; }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="huiyuan"></param>
        /// <returns></returns>
        public int Add(Huiyuan huiyuan)
        {
            try
            {
                MyContext.huiyuans.Add(huiyuan);
                return MyContext.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        } 
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public List<Huiyuan> GetHuiyuans()
        {
            try
            {
                return MyContext.huiyuans.ToList();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //修改
        public int Update(Huiyuan huiyuan)
        {
            try
            {
                var Upd = MyContext.huiyuans.Find(huiyuan.id);
                if (Upd != null)
                {
                    Upd.Beizhu = huiyuan.Beizhu;
                    Upd.Email = huiyuan.Email;
                    Upd.Pic = huiyuan.Pic;
                    Upd.Pwd = huiyuan.Pwd;
                    Upd.Name = huiyuan.Name;
                    Upd.Phone=huiyuan.Phone;
                    Upd.Sex=huiyuan.Sex;
                    Upd.UserName = huiyuan.UserName;

                }
                return MyContext.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
